//jes论坛菜单
Jes.Fmenu ={
	init : function(){
		if(!Jes.userSess()) return;
		//Jes.cBtn('../../oppor/html/desk.html');
		//Jes('add').onclick=function(){Jes.Fmenu.save();}//save
		//Jes('close').onclick=function(){Jes.hide('div_detail');}//save
		this.query();
	}
	,query : function(){
		var html = ['<ul id="ajax_tree" class="dhtmlgoodies_tree">'];
		Jes.get("TJesFmenu",{param:{id:'0'}},function(data){
			html.push('<li><a href="javascript:void(0);" id="'+data.id+'" onclick="Jes.Fmenu.opTreeNode(\''+data.id+'\',\''+data.name+'\');">'+data.name+'</a>');
			html.push('<ul><li parentId="'+data.id+'" class="loading.gif"><a href="javascript:void(0);">Loading...</a></li></ul></li>');
			html.push('</ul>');
			Jes.html('fmenu_tree',html);
			initTree();//初始化树
			initContextMenu();//初始化菜单
			expandAll('ajax_tree');
		});
	}
	,opTreeNode : function(id){
		Jes.show('div_detail');
		var pname=(!id)?'':Jes.html(Jes.tag('A',Jes(id).parentNode.parentNode.parentNode)[0]);
		if(id=='0'){
			Jes.html('div_detail','<h3>'+pname+'</h3>')
		}else{
			Jes.html('div_detail',Jes.html('div_op'));
			Jes.vals({op_title:'栏目菜单新增',id:'',name:'',pname:'',status:1,orderidx:0,remark:'',createtime:'new',modifytime:'now',pname:pname});
			Jes.get("TJesFmenu",{param:{id:id},title:"栏目菜单编辑",isLoad:false},function(data){
				if(!Jes.isNull(id)){
					Jes.vals(data);
					Jes.Upload.showImg('ta_query1_pic',data.pic,217,62);
					Jes.each(['ispic','islink','isnew','istnew'],function(i,item){
						Jes.Fmenu.sel(item);
					})
				}
			});
		}
		//alert(Jes.html('op_button'))
	}
	,save : function(){
		var param = Jes.vals('form1',0);
		if(param ==null) return;
		if(param.ispic=='1'){
			if(!param['ta_query1_pic.upname']){
				alert('请上传栏目图片!');
				return;
			}
		}
		param.pic = param['ta_query1_pic.upname'];
		Jes.save("TJesFmenu",{param:param},function(data){
			alert('保存成功!');
			if(Jes.val('id')=='') loadNodeByParentId(data.parentid);//重新读取父节点
			else loadNodeById(data.id,data.name);//重新读取父节点
			Jes.hide('div_detail');
		});
	}
	,sel : function(el){
		var val = Jes.val(el);
		if(val=='1') Jes.show(el+'_div');
		else Jes.hide(el+'_div');
	}
	,sync :function(){
		Jes.save('jes.syncfmenu',{param:{}},function(data){alert(data);});
	}
}

//读取子节点(固定方法)
function loadTreeChildNodes(ulId,parentId){
	DWRUtil.useLoadingMessage("正在读取数据...");
	var html = '';
	Jes.query('fmenu_pid_query_sql@bs',{param:{pId:parentId},isLoad:false},function(data){
		for(var i=0;i<data.length;i++){
			html += '<li><a href="javascript:void(0);" id="'+data[i].id+'" onclick="Jes.Fmenu.opTreeNode(\''+data[i].id+'\',\''+data[i].name+'\');">'+data[i].name+'</a><ul><li parentId="'+data[i].id+'" class="loading.gif"><a href="javascript:void(0);">Loading</a></li></ul></li>';
		}
		Jes.html(ulId,html);
		if(html == ''){
			Jes.tag('IMG',Jes(ulId).parentNode)[0].style.visibility = "hidden";
			Jes.hide(ulId);
		}
		parseSubItems(ulId,parentId);
	});
}

function addTreeNode(pId,pTitle){
	Jes.Fmenu.opTreeNode();
	Jes.vals({'parentid':pId,'pname':pTitle});
}


function editTreeNode(id,pTitle){
	Jes.Fmenu.opTreeNode(id);
}

function deleteTreeNode(id,title){
	Jes.exec({ids:id,sql:"fmenu_delete_hql@bs"},function(){
		Jes.hide('div_detail');
	});
}